package com.gxsyh.nantie.statements.management.provider.util;

import com.gxsyh.nantie.statements.management.provider.domain.ApartmentStatements;
import com.gxsyh.nantie.statements.management.provider.domain.TbOrder;
import com.gxsyh.nantie.statements.management.provider.service.TbDepartmentService;
import com.gxsyh.nantie.statements.management.provider.service.TbOrderService;

import javax.annotation.Resource;
import java.util.List;

public class ApartmentOrderCountUtil {


    @Resource
    private  TbOrderService tbOrderService;

    @Resource
    private TbDepartmentService tbDepartmentService;

    /**
     * 计算次级公寓下的消费情况和人次
     * @param payDepartmentId，name，tbOrderList
     */
    public  ApartmentStatements count(Long payDepartmentId,String name,List<TbOrder> tbOrderList)
    {
        Double subsidy=new Double(0);
        Double amountConsumption=new Double(0);
        Integer cashCount=new Integer(0);
        Integer subsidyCount=new Integer(0);
        Double cashConsumption=new Double(0);
        Double subsidyConsumption=new Double(0);
        for (TbOrder list: tbOrderList)
        {
            amountConsumption+=list.getAmountConsumption();
            if (list.getSubsidy()==0)
            {
                cashCount++;
                cashConsumption+=list.getAmountConsumption();
            }else{
                subsidyCount++;
                subsidy+=list.getSubsidy();
                subsidyConsumption+=list.getAmountConsumption();
            }
        }
        ApartmentStatements apartmentStatements=new ApartmentStatements();
        apartmentStatements.setDepartmentName(name);
        apartmentStatements.setId(payDepartmentId);
        apartmentStatements.setAmountConsumption(amountConsumption);
        apartmentStatements.setSubsidy(subsidy);
        apartmentStatements.setOrderCount(tbOrderList.size());
        apartmentStatements.setCashCount(cashCount);
        apartmentStatements.setSubsidyCount(subsidyCount);
        apartmentStatements.setCashConsumption(cashConsumption);
        apartmentStatements.setSubsidyConsumption(subsidyConsumption);

        return apartmentStatements;
    }


    /**
     * 计算中心公寓的消费情况和人次
     * @param payDepartmentId，name，tbOrderList
     */
    public ApartmentStatements SummaryCount(Long payDepartmentId,String name,List<ApartmentStatements> apartmentStatementsList)
    {
        Double subsidy=new Double(0);
        Double amountConsumption=new Double(0);
        Integer cashCount=new Integer(0);
        Integer subsidyCount=new Integer(0);
        Double cashConsumption=new Double(0);
        Double subsidyConsumption=new Double(0);
        Integer orderCount=new Integer(0);
        for (ApartmentStatements list: apartmentStatementsList)
        {

            subsidy+=list.getSubsidy();
            System.out.println(subsidy);
            amountConsumption+=list.getAmountConsumption();
            cashCount+=list.getCashCount();
            subsidyCount+=list.getSubsidyCount();
            cashConsumption+=list.getCashConsumption();
            subsidyConsumption+=list.getSubsidyConsumption();
            orderCount+=list.getOrderCount();
        }
        ApartmentStatements apartmentStatements=new ApartmentStatements();
        apartmentStatements.setDepartmentName(name);
        apartmentStatements.setId(payDepartmentId);
        apartmentStatements.setAmountConsumption(amountConsumption);
        apartmentStatements.setSubsidy(subsidy);
        apartmentStatements.setOrderCount(orderCount);
        apartmentStatements.setCashCount(cashCount);
        apartmentStatements.setSubsidyCount(subsidyCount);
        apartmentStatements.setCashConsumption(cashConsumption);
        apartmentStatements.setSubsidyConsumption(subsidyConsumption);

        return apartmentStatements;
    }
}
